package com.chen.palmar.common.override;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Chen on 2017/3/20.
 * 功能描述：
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {

    private int space;

    public SpaceItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

        if (parent.getChildAdapterPosition(view) == 0) {
            outRect.left = space * 2;
            outRect.right = space;
        } else if (parent.getChildAdapterPosition(view) == parent.getChildCount() - 1) {
            outRect.right = space * 2;
            outRect.left = space;
        } else {
            outRect.left = space;
            outRect.right = space;
        }
    }
}
